package com.dream.keigezhushou.Activity.acty.listen;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.dream.keigezhushou.Activity.BaseActivity;
import com.dream.keigezhushou.Activity.adapter.PersonalAdapter;
import com.dream.keigezhushou.Activity.pop.CustomLinearLayoutManager;
import com.dream.keigezhushou.Activity.pop.MoreWindow;
import com.dream.keigezhushou.Activity.pop.MoreWindowToMusicMessage;
import com.dream.keigezhushou.Activity.view.CircleImageView;
import com.dream.keigezhushou.Activity.view.NestedScrollViewBottom;
import com.dream.keigezhushou.Activity.wigdt.DividerItemDeoration;
import com.dream.keigezhushou.R;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PersonalActivity extends BaseActivity implements View.OnClickListener{

    @BindView(R.id.iv_return)
    ImageView ivReturn;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_person_recommend)
    ImageView ivPersonRecommend;
    @BindView(R.id.rv_list)
    RecyclerView rvList;
    @BindView(R.id.scroll_bottom)
    NestedScrollViewBottom scrollBottom;
    @BindView(R.id.ivBBAlbum)
    CircleImageView ivBBAlbum;
    @BindView(R.id.tvBBTitle)
    TextView tvBBTitle;
    @BindView(R.id.tvBBSinger)
    TextView tvBBSinger;
    @BindView(R.id.ib_Next)
    ImageView ibNext;
    @BindView(R.id.ib_Play_pause)
    ImageView ibPlayPause;
    @BindView(R.id.ib_previous)
    ImageView ibPrevious;
    @BindView(R.id.iv_more)
    ImageView ivMore;
    @BindView(R.id.rlBottomBar)
    RelativeLayout rlBottomBar;
    @BindView(R.id.activity_personal)
    LinearLayout activityPersonal;

    private ArrayList<String> a;
    private PersonalAdapter personalAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_personal);
        ButterKnife.bind(this);

        initView();
        initData();
    }

    //初始化界面
    protected void initView(){

        tvTitle.setText("个性推荐");

        a=new ArrayList<String>();
        for (int i = 'A'; i < 'L'; i++) {
            a.add("" + (char) i);
        }
    }

    //初始化数据
    protected void initData(){

        ivReturn.setOnClickListener(this);

        //滑动到底部的监听
        scrollBottom.setScrollBottomListener(new NestedScrollViewBottom.ScrollBottomListener() {
            @Override
            public void scrollBottom() {

                Toast.makeText(getApplicationContext(),"没有更多了~",Toast.LENGTH_SHORT).show();
            }
        });

        //RecyclerView创建适配器

        personalAdapter = new PersonalAdapter(this, a);
        rvList.setAdapter(personalAdapter);

//        svPersonalrecommend.scrollTo(0,0);
//        svPersonalrecommend.fullScroll(View.FOCUS_UP);
//        svPersonalrecommend.smoothScrollTo(0,0);


        //设置RecycleView不能滑动
        CustomLinearLayoutManager linearLayoutManager = new CustomLinearLayoutManager(PersonalActivity.this);
        linearLayoutManager.setScrollEnabled(false);
        rvList.setLayoutManager(linearLayoutManager);
        //设置RecycleView不能滑动结束


//        rvList = (RecyclerView) findViewById(R.id.rcv_personal);
        rvList.addItemDecoration(new DividerItemDeoration(this, DividerItemDeoration.VERTICAL_LIST));


        personalAdapter.addHeaderView(View.inflate(this, R.layout.golde30s_collecte_headerview, null));
        personalAdapter.setOnItemClickListener(new MyItemClickListener() {
            @Override
            public void onItemClick(int position) {

//                Toast.makeText(PersonalActivity.this, "Item播放", Toast.LENGTH_SHORT).show();

            }

            @Override
            public void onBtnClick(int position) {

                final MoreWindow moreWindow = new MoreWindow(View.inflate(PersonalActivity.this, R.layout.golde30s_pupwindow, null), PersonalActivity.this, RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT);
                moreWindow.showPopAtLocation(rvList, Gravity.BOTTOM);
                moreWindow.setItemListener(new MoreWindow.ItemClickListener() {
                    @Override
                    public void onClick() {


//                        Toast.makeText(PersonalActivity.this, "好样", Toast.LENGTH_SHORT).show();

                    }

                    @Override
                    public void onSingDetail() {


                        WindowManager wm = (WindowManager) PersonalActivity.this
                                .getSystemService(Context.WINDOW_SERVICE);

                        int width = wm.getDefaultDisplay().getWidth();
                        int height = wm.getDefaultDisplay().getHeight();


                        MoreWindowToMusicMessage moreWindowToMusicMessage = new MoreWindowToMusicMessage(View.inflate(PersonalActivity.this, R.layout.pop_musicmessage, null), PersonalActivity.this, width, ViewGroup.LayoutParams.WRAP_CONTENT);
//                       moreWindow.setBackColorState(0);
                        moreWindowToMusicMessage.showPopAtLocation(rvList, Gravity.BOTTOM);
                        moreWindow.backGroundAlpha(0.4f);


                    }
                });


//                Toast.makeText(PersonalActivity.this, "更多哦", Toast.LENGTH_SHORT).show();

            }
        });
    }


    //点击事件的实现

    @Override
    public void onClick(View view) {

        switch (view.getId()){

            case R.id.iv_return:

                //返回
                finish();
                break;
        }
    }

    public interface MyItemClickListener {
        public void onItemClick(int position);

        public void onBtnClick(int position);
    }

}
